package com.workstudy.controller;

import com.github.pagehelper.PageInfo;
import com.workstudy.model.LogModel;
import com.workstudy.service.LoginlogService;
import com.workstudy.support.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import zhibi.common.support.base.Page;
import zhibi.common.support.mybatis.example.Example;
import zhibi.common.support.mybatis.example.ExampleType;
import zhibi.common.support.mybatis.example.ExampleUtil;

@Controller
@RequestMapping("log")
public class LoginLogController extends BaseController {

    @Autowired
    private LoginlogService loginlogService;

    @RequestMapping("list")
    public String list(LogModel logModel, Page page, Model model, String date) {
        Example example = ExampleUtil.getInstance()
                .addParam("u.no", logModel.getUserno(), ExampleType.Operation.LIKE)
                .addParam("u.name", logModel.getUsername(), ExampleType.Operation.LIKE)
                .addParam("l.addtime", date, ExampleType.Operation.LIKE)
                .addParam("u.type", "student")
                .addOrder("l.addtime", ExampleType.OrderType.DESC)
                .getExample();
        PageInfo<LogModel> pageInfo = loginlogService.selectModel(example, page);
        setModelAttribute(model, pageInfo);
        return "log/list";
    }
}